package ddd;
import ddd.damage.DamageManager;

/**
 * @author dengzhiyuan
 * @version 1.0
 * @time 2021/5/24 18:13
 */
public class CombatServiceImpl implements CombatService{

//    private WeaponRepository weaponRepository;
    private DamageManager damageManager;

    @Override
    public void performAttack(Player player, Monster monster) {
        Weapon weapon = player.getWeaponId();
        int damage = DamageManager.calculateDamage(player, weapon, monster);
        if (damage > 0) {
            //monster.takeDamage(damage); // （Note 1）在领域服务里变更Monster
        }
        //省略掉Player和Weapon可能受到的影响
        if (!monster.isAlive()) {
            player.receiveExp(10); // 收到经验
            //如果再加上“升级后奖励XXX”呢？“更新XXX排行”呢？依此类推，后续这种代码将无法维护。所以我们需要介绍一下领域层最后一个概念：领域事件（Domain Event）。
            if (player.canLevelUp()) {
                player.levelUp(); // 升级
            }
        }
    }

}
